/*************************************************
Author: Aven 
Date: 12/03/2013
Description:
Notes:
*************************************************/

#ifndef __CMagicDoorMgr_h__
#define __CMagicDoorMgr_h__

#include "commmsg.h"
#include "CMagicDoorCfg.h"

class MsgReqMagicDoor;
class MsgAnsMagicDoor;
class CPlayerBaseInfo;
class CPlayerDetailInfo;
class CPlayerSnsDetailInfo;
class CPlayerOnlineData;
class CPlayerCacheData;
class CDropItem;
class CClanEntry;
class CBattleRole;
class CMagicDoorMonUnit;
class MsgReqGMPlayer;
class MsgAnsGMPlayer;

class CMagicDoorMonGroup
{
public:
    CMagicDoorMonGroup()
    {
        Clear();
    }

    virtual ~CMagicDoorMonGroup()
    {
    }

    void Clear()
    {
        _uiMapID = 0;
        _uiNormalID = 0;
        _uiSpecialID = 0;
    }

    unsigned int GetMapID() const {return _uiMapID;}
    unsigned int GetNormalID() const {return _uiNormalID;}
    unsigned int GetSpecialID() const {return _uiSpecialID;}

    void SetMapID(unsigned int uiVal) {_uiMapID = uiVal;}
    void SetNormalID(unsigned int uiVal) {_uiNormalID = uiVal;}
    void SetSpecialID(unsigned int uiVal) {_uiSpecialID = uiVal;}

private:
    unsigned int _uiMapID;
    unsigned int _uiNormalID;
    unsigned int _uiSpecialID;
};

class CMagicDoorMgr
{
public:
    enum CMD_MAGIC_DOOR_SUB_TAG
    {
        CMD_MAGIC_DOOR_SUB_GET_INFO = 1,        //获取魔界门信息
        CMD_MAGIC_DOOR_SUB_PAY = 2,             //充能
        CMD_MAGIC_DOOR_SUB_GET_RANK = 3,        //获取充能排行
        CMD_MAGIC_DOOR_SUB_CLEAR_CD = 4,        //清除CD时间
        CMD_MAGIC_DOOR_SUB_OPEN_DOOR = 5,       //打开传送门
        CMD_MAGIC_DOOR_SUB_GET_MONSTER = 6,     //获取怪物信息
        CMD_MAGIC_DOOR_SUB_BATTLE = 7,          //战斗
        CMD_MAGIC_DOOR_SUB_NOTIFY_MAGIC_INFO = 8, //广播魔界门信息
        CMD_MAGIC_DOOR_SUB_NOTIFY_MONSTER_INFO = 9, //广播怪物信息
        CMD_MAGIC_DOOR_SUB_NOTIFY_OPEN_DOOR = 10, //广播魔界门开启
    };

    enum ENUM_MAGIC_DOOR_MACRO_TAG
    {
        MAGIC_DOOR_ADD_EXP_ONE_PAY = 10, //每次充能魔界门获得的经验
        MAGIC_DOOR_ENERGY_INCR = 5, //精力每次增长5点
        MAGIC_DOOR_TIME_AFTER_OPEN = 1800,//开启后怪物存在的秒值
        MAGIC_DOOR_OPEN_TIME_PER_DAY = 1, //每个家族开启次数限制
        MAGIC_DOOR_BATTLE_DEAD_CD_TIME = 20, //战斗死亡冷却时间
    };

    CMagicDoorMgr()
    {
        SetCheckJoinDay(true);
        _stMonGroup.Clear();
    }

    virtual ~CMagicDoorMgr()
    {
    }

    int LoadConfig(const char* szCfgPath);

    int FindLevelConfig(int iLevel)
    {
        return _stMagicDoorCfg.FindLevelConfig(iLevel);
    }

    CMagicDoorLevelCfgData& GetLevelConfig(int iIndex)
    {
        return _stMagicDoorCfg.GetLevelConfig(iIndex);
    }

    int FindConsumeConfig(int iTimes)
    {
        return _stMagicDoorCfg.FindConsumeConfig(iTimes);
    }

    CMagicDoorConsumeCfgData& GetConsumeConfig(int iIndex)
    {
        return _stMagicDoorCfg.GetConsumeConfig(iIndex);
    }

    //获取魔界门信息
    int GetMagicDoorInfo(CPlayerDetailInfo& stPlayerDetail,
            MsgAnsMagicDoor& stAns);

    int CheckMagicDoorDataZero(CClanEntry& stClanEntry);

    int GetPayContriTimes(CPlayerDetailInfo& stPlayerDetail, bool bTotal);

    void CheckPayContriTimes(CPlayerDetailInfo& stPlayerDetail, CClanEntry& stClanEntry);

    int GetTotalPayTimes(CPlayerDetailInfo& stPlayerDetail, CClanEntry& stClanEntry);

    void AddTotalPayTimes(CPlayerDetailInfo& stPlayerDetail, CClanEntry& stClanEntry);

    //充能 
    int PayContribute(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerSnsDetailInfo& stPlayerSnsDetail,
            CPlayerOnlineData& stPlayerOnline, MsgAnsMagicDoor& stAns);

    //获取充能排行榜
    int GetPayContributeRank(CPlayerDetailInfo& stPlayerDetail,
            MsgAnsMagicDoor& stAns);

    //开启魔界传送门
    int MagicDoorOpen(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail);

    //奖励充能榜前三名礼包
    int AwardToContributeRank(unsigned int uiClanID);

    //活动到期结束处理逻辑
    int TimeUpCloseMagicDoor(unsigned int uiClanID);

    int CloseMagicDoor(CClanEntry& stClanEntry, int iStatus);

    int NotifyActInfoToAllClanMembers(unsigned int uiClanID);

    //下发星门开启或者关闭消息给家族成员
    int NotifyActInfoToAllClanMembers(CClanEntry& stClanEntry);

    //下发活动结束消息给在线家族成员
    int NotifyActCloseTipsToAllClanMembers(CClanEntry& stClanEntry,
            int iCloseStat);

    //奖励家族成员贡献度
    int AwardToAllClanMembers(unsigned int uiClanID, int iContributeAward);

    //获取怪物信息
    int GetMagicDoorMonsterInfo(CPlayerDetailInfo& stPlayerDetail,
            MsgAnsMagicDoor& stAns);

    CMagicDoorMonGroup& GetMagicDoorMonGroup();

    int InitMagicDoorMonsterInfo(CPlayerDetailInfo& stPlayerDetail);

    //触发战斗
    int GetMagicDoorBattleCamera(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline,
            CPlayerCacheData& stPlayerCache, MsgReqMagicDoor& stReq,
            MsgAnsMagicDoor& stAns);

    //修正战斗开始前数据
    int ReviseBeforeBattle(int iBossBattleID);

    int DealPlayerAfterBattle(CPlayerCacheData& stPlayerCache,
            CClanEntry& stClanEntry, MsgAnsMagicDoor& stAns,
            CMagicDoorMonUnit& stMonsterUnit, int iBattleResult);

    int MagicDoorRoleAward(CPlayerCacheData& stPlayerCache,
            CClanEntry& stClanEntry, MsgAnsMagicDoor& stAns,
            CMagicDoorMonUnit& stMonsterUnit);

    int MagicDoorRoleAwardItem(unsigned int uiGID, int iRepu, int iExp,
            int iContri, int iSilver, CDropItem& stDropItem);

    int DealClanAfterBattle(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail, CClanEntry& stClanEntry);

    int NotifyMapUsers(CPlayerDetailInfo& stPlayerDetail,
            CClanEntry& stClanEntry, int iSubCmd, bool bNotifySelf);

    int NotifyAllClanUsers();

    int GMSetMonsterHP(CPlayerDetailInfo& stPlayerDetail, int iNewHP,
            int iMonIndex);

    int GMDealMagicDoor(CPlayerDetailInfo& stPlayerDetail,
            CPlayerSnsDetailInfo& stPlayerSnsDetail, MsgReqGMPlayer& stReq,
            MsgAnsGMPlayer& stAns);

    int GetAtkValue() const {return _iAtkValue;}
    void SetAtkValue(int iVal) {_iAtkValue = iVal;}

    int GetMonNowHP() const {return _iMonNowHP;}
    void SetMonNowHP(int iVal) {_iMonNowHP = iVal;}

    bool GetCheckJoinDay() const {return _bCheckJoinDay;}
    void SetCheckJoinDay(bool bVal) {_bCheckJoinDay = bVal;}

private:
    bool _bCheckJoinDay;
    int _iAtkValue;
    int _iMonNowHP;
    CMagicDoorMonGroup _stMonGroup;
    CMagicDoorConfig _stMagicDoorCfg; 
};

#endif //__CMagicDoorMgr_h__

